package com.shwread.android.qysw.activity.healthy;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.shwread.android.qysw.step.adapter.GroupManageAdapter;
import com.shwread.android.qysw10000227.R;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by Fantasy on 16/3/27.
 */
public class GroupPKActivity extends FragmentActivity {
    public static final int TAB_MY_GAME = 0;
    public static final int TAB_MY_CREATE = 1;
    public GroupManageAdapter groupManageAdapter;
    @InjectView(R.id.back_btn)
    ImageView backBtn;
    @InjectView(R.id.back_text)
    TextView backText;
    @InjectView(R.id.title_text)
    TextView titleText;
    @InjectView(R.id.right_text)
    TextView rightText;
    @InjectView(R.id.right_img)
    ImageView rightImg;
    @InjectView(R.id.my_game_tab)
    RadioButton myGameTab;
    @InjectView(R.id.my_create_tab)
    RadioButton myCreateTab;
    @InjectView(R.id.main_tab_group)
    RadioGroup mainTabGroup;
    @InjectView(R.id.viewpager)
    ViewPager viewpager;
    @InjectView(R.id.fragment_container)
    LinearLayout fragmentContainer;
    @InjectView(R.id.create_game_button)
    RelativeLayout createGameButton;
    @InjectView(R.id.create_game_text)
    TextView createGameText;
    @InjectView(R.id.left_line)
    View leftLine;
    @InjectView(R.id.right_line)
    View rightLine;

    private int isNeedStep = 0;//0不需要,1需要

    public int getIsNeedStep() {
        return isNeedStep;
    }

    public void setIsNeedStep(int isNeedStep) {
        this.isNeedStep = isNeedStep;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.h_group_pk);
        ButterKnife.inject(this);
        final Intent intent = getIntent();
        isNeedStep = intent.getIntExtra("isNeedStep", 0);
        if (isNeedStep == 1) {
            myGameTab.setText("我的竞赛");
            titleText.setText("目标竞赛");
            createGameText.setText("创建竞赛");
            rightText.setText("历史竞赛");
            rightText.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent1 = new Intent(GroupPKActivity.this, GroupPKHistoryActivity.class);
                    intent1.putExtra("isNeedStep", 1);
                    startActivity(intent1);
                }
            });
        } else {
            myGameTab.setText("我的团赛");
            titleText.setText("组团赛");
            rightText.setText("历史团赛");
            createGameText.setText("创建团赛");
            rightText.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent2 = new Intent(GroupPKActivity.this, GroupPKHistoryActivity.class);
                    intent2.putExtra("isNeedStep", 0);
                    startActivity(intent2);
                }
            });
        }
        groupManageAdapter = new GroupManageAdapter(getSupportFragmentManager());
        viewpager.setAdapter(groupManageAdapter);
        myGameTab.setChecked(true);
        viewpager.setCurrentItem(TAB_MY_GAME);
        viewpager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                switch (position) {
                    case TAB_MY_GAME:
                        myGameTab.setChecked(true);
                        myCreateTab.setChecked(false);
                        leftLine.setVisibility(View.VISIBLE);
                        rightLine.setVisibility(View.INVISIBLE);
                        break;
                    case TAB_MY_CREATE:
                        myCreateTab.setChecked(true);
                        myGameTab.setChecked(false);
                        leftLine.setVisibility(View.INVISIBLE);
                        rightLine.setVisibility(View.VISIBLE);
                        break;
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        backBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        myCreateTab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                viewpager.setCurrentItem(TAB_MY_CREATE);
                leftLine.setVisibility(View.INVISIBLE);
                rightLine.setVisibility(View.VISIBLE);
            }
        });
        myGameTab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                viewpager.setCurrentItem(TAB_MY_GAME);
                leftLine.setVisibility(View.VISIBLE);
                rightLine.setVisibility(View.INVISIBLE);
            }
        });
        createGameButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(GroupPKActivity.this, GroupPKCreateActivity.class);
                intent.putExtra("isNeedStep", isNeedStep);
                startActivity(intent);
            }
        });
    }
}
